﻿#include <stdio.h>
#include <conio.h>
#include <string>
#include "Hamcon.h"
#define MAX 100
//ham readers
void them_DG(int &Soluong_DG);
void xuat_tat_ca_DG();
void xuat_DG_vi_tri_i(int vitridocgia);
void Sua_DG_Vi_Tri_Thu_I();
void xoa_DG_vi_tri_I();
void xoa_DG_vi_tri_I();
void TK_DG_CMND();
void TK_DG_Ten();
void TKe_DG();
//ham book
void them_Sach(int &soluong_sach);
void xuat_tat_ca_sach();
void Sua_sach_Vi_Tri_Thu_I();
void xoa_sach_vi_tri_I();
void TK_sach_ISBN();
void TK_sach_Ten();
//

void main()
{
	int Soluong_DG=0, soluong_sach=0;
	int select; int select_Con; bool flagmenu=true; char Back; bool fla=true;
	do
	{
		printf("\t Quan Ly Thu Vien Truong KHTN \n");
		printf("-------------------------------------------------------\n");
		printf("1.Quan Ly Doc Gia \n 2.Quan Ly Sach \n 3.Lap Phieu Muon Sach \n 4.Lap Phieu Tra Sach \n 5.Thong ke Co Ban \n 6.Thoat \n");
		printf(" Chon: ");
		scanf("%d",&select);
		switch(select)
		{
		case 1:system("cls");
			printf(" Ban da chon chuc nang: Quan Ly Doc Gia \n");
			do
			{
				printf("1.Them Doc Gia \n 2.Xuat Thong Tin Doc Gia \n 3.Chinh Sua Thong Tin Mot Doc Gia \n 4.Xoa Thong Tin Mot Doc Gia \n 5.Tim Kiem Doc Gia Theo CMND \n 6.Tim Kiem Doc Gia Theo Ho Ten \n 7.Quay Lai Menu Chinh \n");
				printf(" Chon: ");
				scanf("%d",&select_Con);
				switch(select_Con)
				{
				case 1:system("cls");
					printf(" Ban Da Chon Chuc Nang: Them Doc Gia \n");
					them_DG(Soluong_DG);
					break;
				case 2:system("cls");
					if(Soluong_DG>0)
					{
						printf(" Ban Da Chon Chuc Nang: Xuat Thong Tin Doc Gia \n");
						xuat_tat_ca_DG();
					}
					else
					{
						printf(" Khong co thong tin doc gia !! Moi ban them doc gia \n");
					}
					break;
				case 3:system("cls");
					if(Soluong_DG>0)
					{
						printf(" Ban Da Chon Chuc Nang: Chinh Sua Thong Tin Mot Doc Gia \n");
						Sua_DG_Vi_Tri_Thu_I();
					}
					else
					{
						printf(" Khong co thong tin doc gia !! Moi ban them doc gia \n");
					}
					break;
				case 4:system("cls");
					if(Soluong_DG>0)
					{
						printf(" Ban Da Chon Chuc Nang: Xoa Thong Tin Mot Doc Gia \n");
						xoa_DG_vi_tri_I();
					}
					else
					{
						printf(" Khong co thong tin doc gia !! Moi ban them doc gia \n");
					}
					break;
				case 5:system("cls");
					if(Soluong_DG>0)
					{
						printf(" Ban Da Chon Chuc Nang: Tim Kiem Thong Tin Doc Gia Theo CMND \n");
						TK_DG_CMND();
					}
					else
					{
						printf(" Khong co thong tin doc gia !! Moi ban them doc gia \n");
					}
					break;
				case 6:system("cls");
					if(Soluong_DG>0)
					{
						printf(" Ban Da Chon Chuc Nang: Tim Kiem Thong Tin Doc Gia Theo Ho Ten \n");
						TK_DG_Ten();
					}
					else
					{
						printf(" Khong co thong tin doc gia !! Moi ban them doc gia \n");
					}
					break;
				case 7:system("cls");
					flagmenu=false;
					break;
				}
			}while(flagmenu); 
			break;
		case 2:system("cls");
			printf(" Ban da chon chuc nang: Quan Ly Sach \n");
			flagmenu=true;
			do
			{
				printf("1.Them Sach \n 2.Xem Thong Tin Sach Co Trong Thu vien \n 3.Chinh Sua Thong Tin Mot Quyen Sach \n 4.Xoa Thong Tin Mot Quyen Sach \n 5.Tim Kiem Mot Quyen Sach Theo ISBN \n 6.Tim Kiem Thong Tin Mot Quyen Sach Theo Ten Sach \n 7. Quay Lai Menu Chinh \n");
				printf(" Chon: ");
				scanf("%d",&select_Con);
				switch(select_Con)
				{
				case 1:system("cls");
						printf("Ban Da Chon Chuc Nang: Them Sach \n");
						them_Sach(soluong_sach);
					break;
				case 2:system("cls");
					if(soluong_sach>0)
					{
						printf("Ban Da Chon Chuc Nang: Xem Thong Tin Sach \n");
						xuat_tat_ca_sach();
					}
					else
					{
						printf(" Khong Co Sach Trong Thu Vien!! Moi Ban Them Sach \n");
					}
					break;
				case 3:system("cls");
					if(soluong_sach>0)
					{
						printf("Ban Da Chon Chuc Nang:  Chinh Sua Thong Tin Sach \n");
						Sua_sach_Vi_Tri_Thu_I();
					}
					else
					{
						printf(" Khong Co Sach Trong Thu Vien!! Moi Ban Them Sach \n");
					}
					
					break;
				case 4:system("cls");
					if(soluong_sach>0)
					{
						printf("Ban Da Chon Chuc Nang: Xoa Thong Tin Sach \n");
						xoa_sach_vi_tri_I();
					}
					else
					{
						printf(" Khong Co Sach Trong Thu Vien!! Moi Ban Them Sach \n");
					}
					break;
				case 5:system("cls");
					if(soluong_sach>0)
					{
						printf("Ban Da Chon Chuc Nang: Tim Kiem Sach Theo Ma ISBN \n");
						TK_sach_ISBN();
					}
					else
					{
						printf(" Khong Co Sach Trong Thu Vien!! Moi Ban Them Sach \n");
					}
					break;
				case 6:system("cls");
					if(soluong_sach>0)
					{
						printf("Ban Da Chon Chuc Nang: Tim Kiem Sach Theo Ten Sach \n");
						TK_sach_Ten();
					}
					else
					{
						printf(" Khong Co Sach Trong Thu Vien!! Moi Ban Them Sach \n");
					}
					break;
				case 7:system("cls");
					flagmenu=false;
					break;
				}
			}while(flagmenu);
			break;
		case 3:system("cls");
			printf(" Ban da chon chuc nang: Lap Phieu Muon Sach \n");
			
			break;
		case 4: system("cls");
			printf(" Ban da chon chuc nang: Lap Phieu Tra Sach \n");
			break;
		case 5:system("cls");
			flagmenu=true;
			printf(" Ban da chon chuc nang: Thong Ke \n");
			do
			{
				printf(" 1.Thong ke So Luong Sach Trong Thu Vien \n 2.Thong Ke So Luong Sach Theo The Loai \n 3.Thong Ke So Luong Doc Gia \n 4.Thong Ke So Luong Doc gia Theo Gioi Tinh \n 5.Thong Ke So Luong Sach dang Duoc Muon \n 6.Thong Ke Danh Sach So Luong Doc Gia Bi Tre Han \n 7.Quay Lai Menu Chinh \n");
				printf(" Chon: ");
				scanf("%d",&select_Con);
				switch(select_Con)
				{
				case 1:system("cls");
					printf(" Ban Da Chon Chuc Nang: Thong Ke So Luong Sach Trong Thu Vien \n");
					if(soluong_sach>0)
					{
						printf(" So Luong Sach Co Trong Thu Vien: %d \n",soluong_sach);
					}
					else
					{
						printf(" Khong Co Sach trong Thu Vien \n");
					}
					break;
				case 2:system("cls");
					printf(" Ban Da Chon Chuc Nang: Thong Ke So Luong Sach Theo The Loai \n");
					if(soluong_sach>0)
					{
						KT_sach_loai();
					}
					else
					{
						printf(" Khong Co Sach trong Thu Vien \n");
					}
					break;
				case 3:system("cls");
					printf(" Ban Da Chon Chuc Nang: Thong Ke So Luong Doc Gia \n");
					if(Soluong_DG>0)
					{
						printf(" So Luong Doc Gia: %d \n",Soluong_DG);
					}
					else
					{
						printf(" Khong Co Doc Gia! \n");
					}
					break;
				case 4:system("cls");
					printf(" Ban Da Chon Chuc Nang: Thong Ke So Luong Doc Gia Theo Gioi Tinh \n");
					if(Soluong_DG>0)
					{
						TKe_DG();
					}
					else
					{
						printf(" Khong Co Doc Gia !! Moi Ban Quay Lai Menu Va Them Doc Gia \n");
					}
					break;
				case 5:system("cls");
					printf(" Ban Da Chon Chuc Nang: Thong Ke So Luong Sach Dang Duoc Muon \n");
					break;
				case 6:system("cls");
					printf(" ban Da Choc Chuc Nang: Thong Ke So Luong Doc Gia Bi tre han \n");
					break;
				case 7:system("cls");
					flagmenu=false;
				}
			}while(flagmenu);
			break;
		case 6:
			fla=false;
			break;
		}	
		if(select<=0 || select>6)
		{
			printf("ban nhap sai!! moi ban nhap lai \n");
		}
	}while(((select<=0 || select>6)) || fla);
	printf(" Ket thuc chuong trinh \n");
	exit(0);
}